Object.defineProperty(exports, "__esModule", {
    value: !0
}), exports.default = void 0;

var _cardUtil = _interopRequireDefault(require("../utils/card-util")), _api = _interopRequireDefault(require("../utils/api")), _signinUtil = require("../public/components/signin-modal/signin-util");

function _interopRequireDefault(t) {
    return t && t.__esModule ? t : {
        default: t
    };
}

var app = getApp(), _default = Behavior({
    attached: function() {
        this.formIds = [];
    },
    methods: {
        _onSubmit: function(t) {
            this.formIds.push(t);
        },
        reportFormIds: function() {
            this.formIds.reduce(function(t, e) {
                return t.then(function() {
                    return app.collectFormId(e);
                });
            }, Promise.resolve());
        },
        _signIn: function(r) {
            var i = this;
            (0, _signinUtil.registerToken)(r).then(function() {
                return wx.showToast({
                    title: "登录成功",
                    duration: 500
                }), _cardUtil.default.loadMyCard();
            }).then(function(t) {
                var e = i.data.mode;
                if (t && t.cardid && "intro" === e) return wx.navigateBack();
                t && t.cardid && "track" !== e || i.navigateTo(r);
            }).then(function() {
                return i.reportFormIds();
            });
        },
        navigateTo: function(t) {
            var e = t.target.dataset.type;
            "create" === e ? this.goto() : "history" === e && this.gotoHistory();
        },
        selectCorpShow: function(t) {
            if (!t.guid) {
                var e = {
                    corpname: t.corpname || "暂无",
                    position: t.position || "暂无",
                    realname: t.realname,
                    mobile: t.mobile,
                    avatar: t.avatar,
                    email: t.email,
                    type: _cardUtil.default.MINICARD_TYPE
                };
                try {
                    this.selectComponent("#corpSelect").getList(e);
                } catch (t) {
                    _cardUtil.default.create(e);
                }
            }
        },
        hideCorpSelect: function() {
            this.selectComponent("#corpSelect").onClose();
        },
        getuserauth: function() {
            return this.getUser || (this.getUser = _api.default.weappuser.getuserauth().catch(function() {
                return {
                    data: {}
                };
            }).then(function(t) {
                var e = t.data, r = e.isverifymobile;
                return {
                    mobile: e.mobile,
                    isverify: r
                };
            })), this.getUser;
        },
        gotoCreate: function(t) {
            var e = this;
            "track" === t.currentTarget.dataset.type ? this.$report("card_create_too_home") : this.$report("card_create"), 
            this.getuserauth().then(function(t) {
                return e.goto(t.isverify ? t : void 0);
            });
        },
        getPage: function() {
            return getCurrentPages()[0];
        },
        goto: function(t) {
            var e = this.getPage(), r = this.data.mode;
            t && e.$put("card.create", t), e.$route("/pages/card/create/create?origin=".concat(r), "intro" === r ? "redirect" : void 0);
        }
    }
});

exports.default = _default;